//
//  WBN_FM_MainCollectionViewCell.m
//  GoodManNews
//
//  Created by 王博男 on 16/1/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "WBN_FM_MainCollectionViewCell.h"
#import "Masonry.h"

@interface WBN_FM_MainCollectionViewCell ()

@property (nonatomic, retain) UIImageView *playImageV;
@property (nonatomic, assign) NSInteger temp;

@end

@implementation WBN_FM_MainCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createView];
    }
    return self;
}

- (void)setCount:(NSInteger)count
{
    self.temp = count;

    [self createButton];
}

- (void)createView
{
    self.imageV = [UIImageView new];
    self.imageV.layer.cornerRadius = 7;
    self.imageV.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.imageV];
    
    
    self.playImageV = [UIImageView new];
    self.playImageV.image = [UIImage imageNamed:@"list_FM_playIcon@3x"];
    [self.contentView addSubview:self.playImageV];
    
    
    self.titleL = [UILabel new];
    self.titleL.textColor = [UIColor colorWithRed:0.076 green:0.007 blue:0.294 alpha:1.000];
    self.titleL.numberOfLines = 0;
    self.titleL.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.titleL];
    
    
    self.nameL = [UILabel new];
    self.nameL.textColor = [UIColor lightGrayColor];
    self.nameL.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.nameL];
    
    

    [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.contentView);
        make.left.mas_equalTo(self.contentView);
        make.width.equalTo(self.contentView.mas_width);
        make.height.equalTo(self.contentView.mas_width);
        
    }];
    
    
    [self.playImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.mas_equalTo(self.imageV);
        make.size.mas_equalTo(CGSizeMake(30, 30));
        
    }];
    
    
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.imageV.mas_bottom);
        make.bottom.equalTo(self.nameL.mas_top);
        make.width.equalTo(self.contentView);
        
    }];
    
    
    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView.mas_bottom).offset(-20);
        make.bottom.equalTo(self.contentView);
        make.width.equalTo(self.contentView);
        
    }];
    
}

- (void)createButton
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor clearColor];
    
    [button setTag:(10000 + self.temp)];

    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:button];
    
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.imageV);
        
    }];
}

- (void)buttonAction:(UIButton *)sender
{
    [self.delegate getIntoPlayerWithNum:sender.tag];
}

@end
